﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
namespace EyesOfTheDragon.Events
{
   
    public interface IEnabled
    {
        bool Enabled { get; set; }
    }
    public interface IPauseable
    {
    }
    public interface IUpdate:IEnabled
    {
        void Update(GameTime gt);
    }
    public class UpdateList
    {
        public bool Paused = false;
        public static UpdateList Instance
        {
            get 
            {
                if (_instance == null)
                    _instance = new UpdateList();
                return _instance; 
            }
        }
        public void Update(GameTime gt)
        {
            LinkedListNode<IUpdate> node = updateableObjects.First;
            if (node.Value != null && node.Value.Enabled)
                node.Value.Update(gt);
            node = node.Next;
            while (node != null && node.Value != null)
            {
                if (node.Value.Enabled && !(Paused && node.Value is IPauseable))
                    node.Value.Update(gt);
                node = node.Next;
            }
        }
        public void add(IUpdate obj)
        {
            updateableObjects.AddLast(obj);
        }
        public bool remove(IUpdate obj )
        {
            return updateableObjects.Remove(obj);
        }
        private LinkedList<IUpdate> updateableObjects = new LinkedList<IUpdate>();
        private static UpdateList _instance;
    }
}
